<?php


namespace app\common\models;


use app\common\traits\BaseModelOptionTrait;
use think\Model;
use think\model\concern\SoftDelete;

class Anniversary extends Model
{
    use BaseModelOptionTrait, SoftDelete;

    protected $table = 'xiangji_anniversaries';

    protected $defaultSoftDelete = 0;

    protected $deleteTime = 'delete_time';

    // 自动维护时间戳
    protected $autoWriteTimestamp = true;

    public static function onBeforeInsert(Model $model)
    {
        if (!$model->bg_img){
            $model->bg_img = 'https://lovetime52.oss-cn-beijing.aliyuncs.com/bg/'. mt_rand(1, 6) .'.jpg';
        }
    }

    public static function onBeforeUpdate(Model $model)
    {
        if (!$model->bg_img){
            $model->bg_img = 'https://lovetime52.oss-cn-beijing.aliyuncs.com/bg/'. mt_rand(1, 6) .'.jpg';
        }
    }

    // 该纪念日的所属用户
    public function user()
    {
        $this->belongsTo(User::class);
    }
}
